/*----------------------------------------------------------------------------*\
| /gamemode/player.lua                 | player extensions               | SRV |
\*----------------------------------------------------------------------------*/

-- Prevent suicide.
function GM:CanPlayerSuicide( ply )
	ply:PrintMessage( HUD_PRINTNOTIFY, "You are not allowed to suicide!" )
	return false
end 

function GM:PlayerLoadout( ply )
	ZDayPlayerLoadout( ply )
end

// This is split so we can call it in other places...namely, when you get
// revived from being ragdolled.
function ZDayPlayerLoadout( ply )

	zday.infection.Cure( ply )
	local myid = ply:UserID()
	goals.status[myid]=false
	deaths.lasthit[myid]=nil
	
	score.generators.repaired[myid]		= 0
	score.generators.refilled[myid]		= 0
	score.generators.destroyed[myid]	= 0
	score.zombies.killed[myid]			= 0
	score.self.died	[myid]				= 0
	score.self.healed[myid]				= 0
	score.others.killed[myid]			= 0
	score.others.healed[myid]			= 0
	score.others.revived[myid]			= 0
	
	
	ply:Freeze(false)
	ply:StripWeapons()
	ply:StripAmmo()
	
	ply:SetArmor(100)
	
	ply:Give( "weapon_fists" )
	if (ZDayConfig["debug"]) then
		ply:Give( "weapon_flashlight" )
		ply:Give( "weapon_9mmpistol" )
	end
	/*ply:Give( "weapon_huntingknife" )
	ply:Give( "weapon_chainsaw" )
	ply:Give( "weapon_9mmpistol" )
	ply:Give( "weapon_revolver" )
	ply:Give( "weapon_assaultrifle" )
	ply:Give( "weapon_submachinegun" )
	ply:Give( "weapon_combatshotgun" )
	ply:Give( "weapon_huntingshotgun" )
	ply:Give( "weapon_rifle" )
	
	ply:GiveAmmo(80,"Pistol",true)
	ply:GiveAmmo(30,"357",true)
	ply:GiveAmmo(64,"SMG1",true)
	ply:GiveAmmo(50,"ar2",true)
	ply:GiveAmmo(24,"Buckshot",true)
	ply:GiveAmmo(30,"SniperRound",true)
	*/
	
end

local function PlayerSpawnServer(ply)
	umsg.Start("PlayerSpawnClient",ply)
	umsg.End()
	ply:SendLua("time.thetime = "..time.thetime)
end
hook.Add("PlayerSpawn", "PlayerSpawnServer", function(ply) PlayerSpawnServer(ply); end)

function PlayerTrace( user, distance )
	local trd = {}
	trd.start  = user:GetShootPos()
	trd.endpos = trd.start + ( user:GetAimVector() * distance )
	trd.filter = user
	
	local tr = util.TraceLine( trd )
	return tr
end

function cmdImpulse(ply,cmd,args)
	if args[1]=="101" and server_settings.Bool( "sv_cheats", 0 ) then
		ply:Give( "weapon_huntingknife" )
		ply:Give( "weapon_flashlight" )
		ply:Give( "weapon_chainsaw" )
		ply:Give( "weapon_9mmpistol" )
		ply:Give( "weapon_revolver" )
		ply:Give( "weapon_assaultrifle" )
		ply:Give( "weapon_submachinegun" )
		ply:Give( "weapon_combatshotgun" )
		ply:Give( "weapon_huntingshotgun" )
		ply:Give( "weapon_rifle" )
		
		ply:GiveAmmo(80,"Pistol",true)
		ply:GiveAmmo(30,"357",true)
		ply:GiveAmmo(64,"SMG1",true)
		ply:GiveAmmo(50,"ar2",true)
		ply:GiveAmmo(24,"Buckshot",true)
		ply:GiveAmmo(30,"SniperRound",true)
	end
end
concommand.Add("zdimpulse",cmdImpulse)
